package com.yixun.qfbao.model.enums;

import org.apache.commons.lang.StringUtils;

import java.io.Serializable;

/**
 * 权限描述字段
 */
public enum DPDescEnum implements Serializable {
	ALL_CHECKED("allChecked", "是否选中所有", null),
	DP_TYPE("dpType", "数据权限类型,对应 DeptPermissionEnum", null),
    EXISTS_PERSONAL("exists", "判断是否存在个人权限", null),
	;

	private final String no;
	private final String des;
	private final Enum parent;

	DPDescEnum(String no, String des, Enum parent) {
		this.no = no;
		this.des = des;
		this.parent = parent;
	}

	public String getNo() {
		return no;
	}

	public String getDes() {
		return des;
	}

	public Enum getParent() {
		return parent;
	}

	public static DPDescEnum getByDescription(String des) {
		if (StringUtils.isBlank(des)) {
			return null;
		}
		for (DPDescEnum menum : values()) {
			if (menum.getDes().equals(des)) {
				return menum;
			}
		}
		return null;
	}

	public static DPDescEnum getByNo(String no) {
		if (StringUtils.isBlank(no)) {
			return null;
		}
		for (DPDescEnum menum : values()) {
			if (menum.getNo().equals(no)) {
				return menum;
			}
		}
		return null;
	}

	public static String getNameByCode(String code) {
		if (!StringUtils.isEmpty(code)) {
			DPDescEnum anEnum = getByNo(code);
			if (anEnum != null) {
				return anEnum.getDes();
			} else {
				return null;
			}
		}
		return null;
	}
}
